package br.com.ozsolucoes.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

@Entity
@NamedQueries({ @NamedQuery(name = "Servico.consultarServicoVingente", query = "select s from Cliente c, Servico s where c.id = s.cliente.id and c.id = :idCliente and s.statusServico = :status"), @NamedQuery(name = "Servico.consultarTodosServicosCliente", query = "select s from Servico s where s.cliente.id = :idCliente"), @NamedQuery(name = "Servico.consultarServicoPorId", query = "select s from Servico s where s.id = :idServico"), })
public class Servico implements Serializable {

	private static final long serialVersionUID = -7871157387132419544L;

	@Id
	@GeneratedValue
	private long id;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Ticket.class, mappedBy = "servico")
	private List<Ticket> tickets;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Ticket.class, mappedBy = "servico")
	private List<Contas> contas;

	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Cliente.class)
	private Cliente cliente;

	@OneToMany(mappedBy = "servico", cascade = CascadeType.ALL)
	private List<ServicoCategoria> servicoCategoria;

	private Date dataInicio;

	private Date dataFim;

	private int diaVencimento;

	private int statusServico;

	private int periodoEmMeses;

	private double valorMensal;
	
	private transient int qtdTickets;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public List<Ticket> getTickets() {
		return tickets;
	}

	public void setTickets(List<Ticket> tickets) {
		this.tickets = tickets;
	}

	public List<Contas> getContas() {
		return contas;
	}

	public void setContas(List<Contas> contas) {
		this.contas = contas;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public Date getDataInicio() {
		return dataInicio;
	}

	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}

	public Date getDataFim() {
		return dataFim;
	}

	public void setDataFim(Date dataFim) {
		this.dataFim = dataFim;
	}

	public int getDiaVencimento() {
		return diaVencimento;
	}

	public void setDiaVencimento(int diaVencimento) {
		this.diaVencimento = diaVencimento;
	}

	public int getPeriodoEmMeses() {
		return periodoEmMeses;
	}

	public void setPeriodoEmMeses(int periodoEmMeses) {
		this.periodoEmMeses = periodoEmMeses;
	}

	public double getValorMensal() {
		return valorMensal;
	}

	public void setValorMensal(double valorMensal) {
		this.valorMensal = valorMensal;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cliente == null) ? 0 : cliente.hashCode());
		result = prime * result + ((contas == null) ? 0 : contas.hashCode());
		result = prime * result + ((dataFim == null) ? 0 : dataFim.hashCode());
		result = prime * result + ((dataInicio == null) ? 0 : dataInicio.hashCode());
		result = prime * result + diaVencimento;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + periodoEmMeses;
		result = prime * result + ((servicoCategoria == null) ? 0 : servicoCategoria.hashCode());
		result = prime * result + statusServico;
		result = prime * result + ((tickets == null) ? 0 : tickets.hashCode());
		long temp;
		temp = Double.doubleToLongBits(valorMensal);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Servico other = (Servico) obj;
		if (cliente == null) {
			if (other.cliente != null)
				return false;
		} else if (!cliente.equals(other.cliente))
			return false;
		if (contas == null) {
			if (other.contas != null)
				return false;
		} else if (!contas.equals(other.contas))
			return false;
		if (dataFim == null) {
			if (other.dataFim != null)
				return false;
		} else if (!dataFim.equals(other.dataFim))
			return false;
		if (dataInicio == null) {
			if (other.dataInicio != null)
				return false;
		} else if (!dataInicio.equals(other.dataInicio))
			return false;
		if (diaVencimento != other.diaVencimento)
			return false;
		if (id != other.id)
			return false;
		if (periodoEmMeses != other.periodoEmMeses)
			return false;
		if (servicoCategoria == null) {
			if (other.servicoCategoria != null)
				return false;
		} else if (!servicoCategoria.equals(other.servicoCategoria))
			return false;
		if (statusServico != other.statusServico)
			return false;
		if (tickets == null) {
			if (other.tickets != null)
				return false;
		} else if (!tickets.equals(other.tickets))
			return false;
		if (Double.doubleToLongBits(valorMensal) != Double.doubleToLongBits(other.valorMensal))
			return false;
		return true;
	}

	public List<ServicoCategoria> getServicoCategoria() {
		return servicoCategoria;
	}

	public void setServicoCategoria(List<ServicoCategoria> servicoCategoria) {
		this.servicoCategoria = servicoCategoria;
	}

	public int getStatusServico() {
		return statusServico;
	}

	public void setStatusServico(int statusServico) {
		this.statusServico = statusServico;
	}

	public int getQtdTickets() {
		return qtdTickets;
	}

	public void setQtdTickets(int qtdTickets) {
		this.qtdTickets = qtdTickets;
	}

}
